﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.dataaccess;
using InHD.commands;
using System.Windows.Input;
using System.Data;
using System.Collections.ObjectModel;
using InHD.utilities;
using System.Windows;
using System.ComponentModel;
using InHD.Properties;

namespace InHD.viewmodels
{
    class ReceiveGoodsViewModel : WorkspaceViewModel
    {
        #region Private variables
        Transaction _trans;
        TransactionRepository _transRepo = null;
        PackageRepository _packageRepo = null;
        TaxRepository _taxRepo = null;
        ProductRepository _proRepo = null;
        CategoryRepository _categoryRepo = null;
        private Package _selectedPackage = null;

        Supplier _currentSupplier = Supplier.CreateSupplier();
        SupplierRepository _curSupplierRepository = null;

        RelayCommand _addProductCommand;
        RelayCommand _removeProductCommand;
        RelayCommand _receiveCommand;

        private RelayCommand _selectCommand;
        private RelayCommand _closeProductsCommand;
        private RelayCommand _searchCommand;
        private RelayCommand _addToPackageCollectionCommand;
        private RelayCommand _changeSaleTypeCommand;
        private RelayCommand _searchsupplierCommand;
        private RelayCommand _chooseProductCommand;

        private bool _isIncludeTax;
        private bool _isWholesale;        

        private ObservableCollection<Package> _pacs=  new ObservableCollection<Package>();
        List<Product> _products;
        private Tax _selectedTax = null;
        private Package _currentPackage;

        private bool _isInvalidSupplierCode = false;
        
        #endregion

        #region Creation
        public ReceiveGoodsViewModel()
        {
            this._transRepo = new TransactionRepository();
            this._packageRepo = new PackageRepository();
            this._taxRepo = new TaxRepository();
            this._proRepo = new ProductRepository();
            this._categoryRepo = new CategoryRepository();
            this._curSupplierRepository = new SupplierRepository();
            this._categoryRepo.LoadAllCategories();
            this._curSupplierRepository.LoadAllSuppliers();

            this.ProductFields = Product.Fields;
            this._products = new List<Product>();
            this._taxRepo.LoadAllTaxTypes();
            Taxs = _taxRepo.GetAllTaxes();
            this._currentPackage = Package.CreatePackage();

            SupplierFields = Supplier.Fields;

            this.SupplierRowIndex = -1;
            this.RowIndex = -1;

            this.InvoiceDate = System.DateTime.Now;
        }
        #endregion

        #region Public fields
        public string StaffUNK;

        public string SerialNo
        {
            get { return this._currentPackage.SerialNo; }
            set { this._currentPackage.SerialNo = value; base.OnPropertyChanged("SerialNo"); }
        }

        public string Description
        {
            get { return this._currentPackage.Description; }
            set { this._currentPackage.Description = value;}
        }

        public string CategoryName
        {
            get { return this._currentPackage.CategoryName; }
            set { this._currentPackage.CategoryName = value; }
        }

        public double UnitPrice
        {
            get { return this._currentPackage.UnitPrice; }
            set
            {
                this._currentPackage.UnitPrice = value;
            }
        }

        public int Quantity
        {
            get { return this._currentPackage.Quantity; }
            set
            {
                this._currentPackage.Quantity = value;
            }
        }

        public int RowIndex { get; set; }

        public List<Tax> Taxs
        {
            get;
            private set;
        }

        public Tax SelectedTax
        {
            get
            {
                return this._selectedTax;
            }
            set
            {
                this._selectedTax = value;
                if (value == null)
                {
                    this.totalIncTax = this.totalExTax;
                }
                else
                {
                    this.totalIncTax = this.totalExTax * (1 + this._selectedTax.Percentage);
                }
                
                OnPropertyChanged("TotalPriceIncTax");
                OnPropertyChanged("TotalPriceTax");
            }
        }

        public bool IsIncludeTax
        {
            get { return this._isIncludeTax; }
            set
            {
                this._isIncludeTax = value;
                base.OnPropertyChanged("IsIncludeTax");
                this.SelectedTax = null;
                base.OnPropertyChanged("SelectedTax");
            }
        }

        public string TotalPriceExTax
        {
            get 
            {
                totalExTax = 0;
                foreach (Package p in this.PackagesCollection)
                {
                    totalExTax += p.PackagePrice;
                }

                OnPropertyChanged("TotalPriceIncTax");
                return Resources.Ex_Tax + this.totalExTax.ToString();
            }
        }

        public string TotalPriceTax
        {
            get 
            {
                return (this.SelectedTax == null) ? Resources.Tax_Title + " 0 %" : Resources.Tax_Title + ((long)(this.SelectedTax.Percentage * 100)).ToString() + " %";
            }
        }

        public string TotalPriceIncTax
        {
            get 
            {
                if (this.SelectedTax != null)
                {
                    this.totalIncTax = this.totalExTax * (1 + this.SelectedTax.Percentage);
                }
                else
                {
                    this.totalIncTax = this.totalExTax;
                }
                return Resources.Inc_Tax + ((long)this.totalIncTax).ToString();
            }
        }

        public bool IsWholesale
        {
            get { return this._isWholesale; }
            set
            {
                this._isWholesale = value;
                base.OnPropertyChanged("IsWholesale");
            }
        }


        public ObservableCollection<Package> PackagesCollection
        {
            get
            {
                return this._pacs;
            }
            set
            {
                if (_pacs != value)
                {
                    this._pacs = value;
                    OnPropertyChanged("PackagesCollection");
                    OnPropertyChanged("TotalPriceExTax");
                }
            }
        }

         private Product _currentProduct = Product.CreateProduct();
        public Product CurrentProduct
        {
            get
            {
                return _currentProduct;
            }
            set
            {
                if (!string.IsNullOrEmpty(((Product)value).Name))
                {
                    for (int i = 0; i < this.PackagesCollection.Count; i++)
                    {
                        Package p = this.PackagesCollection[i];
                        if (!string.IsNullOrEmpty(p.ProductUNK) && p.ProductUNK.Equals(((Product)value).ProductUNK))
                        {
                            int tmp2 = GetRowIndexByItem(SelectedPackage);
                            Package tmpPack = this.PackagesCollection[tmp2];
                            this.PackagesCollection.RemoveAt(tmp2);
                            this.PackagesCollection.Insert(tmp2, tmpPack); 
                                MessageBox.Show(Resources.Product_Existing, Resources.App_Title, MessageBoxButton.OK, MessageBoxImage.Information);
                            this.SelectedPackage = this.PackagesCollection[i];
                            OnPropertyChanged("SelectedPackage");
                            return;
                        }
                    }

                    string description = ((Product)value).Description;
                    string serialNo = ((Product)value).SerialNo;
                    double price = this._isWholesale ? ((Product)value).WholesalePrice : ((Product)value).RetailPrice;
                    this._currentPackage = Package.CreateBusinessPackage(serialNo, description, ((Product)value).CategoryName, price, 1, ((Product)value).Name);

                    this._currentPackage.PackageUNK = "Pac-" + Guid.NewGuid().ToString();
                    this._currentPackage.ProductUNK = ((Product)value).ProductUNK;

                    this._currentPackage.SaveRetail = ((Product)value).RetailPrice;
                    this._currentPackage.SaveWholesale = ((Product)value).WholesalePrice;
                    this._currentPackage.SaveImportPrice = ((Product)value).ImportPrice;
                    int temp = this.GetRowIndexByItem(this.SelectedPackage);
                    this.PackagesCollection[temp] = this._currentPackage;
                    this.PackagesCollection[temp].PropertyChanged += EntityViewModelPropertyChanged;
                    this.PackagesCollection[temp].Quantity = 1;
                    OnPropertyChanged("SelectedPackage");
                }
            }
        }

        public Package SelectedPackage
        {
            get
            {
                return this._selectedPackage;
            }

            set
            {
                this._selectedPackage = value;
            }
        }

        private int GetRowIndexByItem(Package package)
        {
            if (package != null && string.IsNullOrEmpty(package.PackageUNK)) return this._pacs.Count - 1;
            for (int i = 0; i < _pacs.Count; i++)
            {
                if (package.PackageUNK.Equals(_pacs[i].PackageUNK) && !string.IsNullOrEmpty(_pacs[i].PackageUNK) && !string.IsNullOrEmpty(package.PackageUNK)) return i;
            }

            return -1;
        }

        public PaymentTypes PaymentType
        {
            get;
            set;
        }

        /// <summary>
        /// Represent DataSource of listview for selecting product in search dialog
        /// </summary>
        public List<Product> Products
        {
            get { return this._products; }
            set { this._products = value; base.OnPropertyChanged("Products"); }
        }

        /// <summary>
        /// Represent ItemSource for select property selected in search dialog
        /// </summary>
        public Dictionary<string, string> ProductFields { get; set; }

        /// <summary>
        /// ItemSource for select category (in search dialog and product workspace)
        /// </summary>
        public List<Category> Categories { get { return this._categoryRepo.GetCategory(); } }

        /// <summary>
        /// Represent Property for search selected in search dialog
        /// </summary>
        public string SelectedProperty { get; set; }

        /// <summary>
        /// Represent Search Criteria typed in search dialog
        /// </summary>
        public string SearchCriteria { get; set; }

        /// <summary>
        /// Represent Category selected in search dialog
        /// </summary>
        public Category SelectedCategory
        {
            get;
            set;
        }

        public string SupplierCode
        {
            get
            { return this._currentSupplier.SupplierCode; }
            set
            {
                this._currentSupplier.SupplierCode = value;
                OnPropertyChanged("SupplierCode");
            }
        }
        public string Name
        {
            get
            { return this._currentSupplier.Name; }
            set
            {
                this._currentSupplier.Name = value;
                OnPropertyChanged("Name");
            }
        }

        public bool IsInvalidSupplierCode
        {
            get
            { return this._isInvalidSupplierCode; }
            set
            {
                this._isInvalidSupplierCode = value;
                OnPropertyChanged("IsInvalidsupplierCode");
            }
        }

        public bool InvoicePreview { get; set; }

        /// <summary>
        /// Returns a command that add new Product.
        /// </summary>
        public ICommand AddNewProductCommand
        {
            get
            {
                if (_addProductCommand == null)
                {
                    _addProductCommand = new RelayCommand(
                        (param) => this.AddProduct(), param => CanAddNewProduct);
                }
                return _addProductCommand;
            }
        }

        /// <summary>
        /// Returns a command that remove the product.
        /// </summary>
        public ICommand RemoveProductCommand
        {
            get
            {
                if (_removeProductCommand == null)
                {
                    _removeProductCommand = new RelayCommand(
                        (param) => this.RemoveProduct(), (param) => this.CanRemove);
                }
                return _removeProductCommand;
            }
        }

        public ICommand ChangeSaleTypeCommand
        {
            get
            {
                if (_changeSaleTypeCommand == null)
                {
                    _changeSaleTypeCommand = new RelayCommand(
                        (param) => this.ChangeSaleType());
                }
                return _changeSaleTypeCommand;
            }
        }

        public ICommand AddToPackageCollectionCommand
        {
            get
            {
                if (_addToPackageCollectionCommand == null)
                {
                    _addToPackageCollectionCommand = new RelayCommand(
                        (param) => this.AddToPackageCollection(), (param) => this.CanAddToPackageCollection);
                }
                return _addToPackageCollectionCommand;
            }
        }

        public ICommand SelectProductForPackageCommand
        {
            get
            {
                if (_chooseProductCommand == null)
                {
                    _chooseProductCommand = new RelayCommand(
                        (param) => this.ChooseProduct());
                }
                return _chooseProductCommand;
            }
        }

        /// <summary>
        /// Returns a command that commit Window
        /// </summary>
        public ICommand ReceiveCommand
        {
            get
            {
                if (_receiveCommand == null)
                {
                    _receiveCommand = new RelayCommand(
                        (param) => this.Receive(param), (param) => this.CanSale);
                }
                return _receiveCommand;
            }
        }

        public ICommand SelectCommand
        {
            get
            {
                if (_selectCommand == null)
                {
                    _selectCommand = new RelayCommand(
                        (param) => this.SelectProduct(), (param)=>this.CanSelectProduct
                        );
                }
                return _selectCommand;
            }
        }

        public ICommand CloseProductsCommand
        {
            get
            {
                if (_closeProductsCommand == null)
                {
                    _closeProductsCommand = new RelayCommand(
                        (param) => this.CloseProducts()
                        );
                }
                return _closeProductsCommand;
            }
        }

        public ICommand SearchCommand
        {
            get
            {
                if (_searchCommand == null)
                {
                    _searchCommand = new RelayCommand(
                        (param) => this.SearchProducts()
                        );
                }
                return _searchCommand;
            }
        }
        #endregion       

        #region Private Helpers

        private void Receive(object param)
        {
            if (this._currentSupplier == null || string.IsNullOrEmpty(this._currentSupplier.SupplierUNK))
            {
                System.Windows.MessageBox.Show("Please select Supplier");
                return;
            }

            if (this.InvoicePreview)
            {
                this.DoPrinter();
            }
            
            double disCount = 0;
            
            this._trans = Transaction.CreateTransaction(
                DateTime.Now,
                this.IsIncludeTax && this.SelectedTax != null ? this.SelectedTax.TaxUNK : "001",
                disCount,
                this.totalIncTax,
                "001",
                TransTypes.PayIn,
                "001",//// account UNK
                this._currentSupplier.SupplierUNK,
                this.StaffUNK,
                0,
                this._currentSupplier.Name,
                "supplier",
                this.IsIncludeTax && this.SelectedTax != null ? this.SelectedTax.Description : string.Empty,
                this.IsIncludeTax && this.SelectedTax != null ? this.SelectedTax.Percentage : 0,
                this.PaymentType);

            this._trans.TransactionUNK = "TRA-" + Guid.NewGuid().ToString();
            if (MessageBox.Show(Resources.Ask_PayNow, Resources.App_Title, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                _trans.ArchiveFlag = _trans.TransactionUNK;
            }
            else
            {
                _trans.ArchiveFlag = string.Empty;
            }

            string result = this._transRepo.AddTransaction(_trans, _pacs, -1);

            if (string.IsNullOrEmpty(result))
            {
                MessageBox.Show(Resources.InHD_TransactionCommited, Resources.App_Title, MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show(Resources.InHD_DB_Error, Resources.App_Title, MessageBoxButton.OK);
            }

            this._pacs.Clear();
        }

        private void DoPrinter() 
        {
            string tableName = "tableContent";
            string[] listColumn = { "1", "2", "3", "4", "5" , "6" };
            DataTable dataTable = new DataTable();
            foreach (string col in listColumn) {
                dataTable.Columns.Add(col);
            }

            int count = 0;
            foreach (Package pack in PackagesCollection)
            { 
                count++;
                DataRow row = dataTable.NewRow();
                row[0] = count;
                row[1] = pack.Description;
                row[2] = "Unit";
                row[3] = pack.Quantity;
                row[4] = pack.UnitPrice;
                row[5] = pack.PackagePrice;
                dataTable.Rows.Add(row);
            }

            InvoicePrinter invoicePrinter = new InvoicePrinter("invoiceTpl298a65f4-9829-4b7e-aa33-cb"); ////Hard code templateID
            invoicePrinter.PutDataTable(tableName, dataTable);
            invoicePrinter.ShowPrintPreview();
        }

        private bool CanSale { get { return (this.totalExTax > 0) ? true : false; } set { } }
        private bool CanRemove { get { return (this.SelectedPackage != null) ? true : false; } set { } }
        private bool CanAddToPackageCollection { get { return (this._currentPackage == null || string.IsNullOrEmpty(this._currentPackage.ProductUNK)) ? false : true; } set { } }
        private bool CanAddNewProduct
        {
            get
            {
                if (string.IsNullOrEmpty(this.SupplierCode))
                {
                    return false;
                }

                if (this._pacs.Count>0 && string.IsNullOrEmpty(this._pacs[this._pacs.Count - 1].PackageUNK))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

        private double totalExTax = 0;
        private double totalIncTax = 0;

        public void EntityViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            //This will get called when the property of an object inside the collection changes
            totalExTax = 0;
            foreach (Package p in this.PackagesCollection)
            {
                totalExTax += p.PackagePrice;
            }

            OnPropertyChanged("TotalPriceExTax"); 
            OnPropertyChanged("TotalPriceIncTax"); 
        }

        private void AddToPackageCollection()
        {
            for (int i = 0; i < this.PackagesCollection.Count; i++)
            {
                Package p = this.PackagesCollection[i];
                if (!string.IsNullOrEmpty(p.ProductUNK) && p.ProductUNK.Equals(this._currentPackage.ProductUNK))
                {
                    MessageBox.Show(Resources.Product_Existing, Resources.App_Title, MessageBoxButton.OK, MessageBoxImage.Information);
                    this.SelectedPackage = p;
                    OnPropertyChanged("SelectedPackage");
                    return;
                }
            }

            int temp = GetRowIndexByItem(this.SelectedPackage);
            this.PackagesCollection[temp] = this._currentPackage;
            this.PackagesCollection[temp].PropertyChanged += EntityViewModelPropertyChanged;
            this.SelectedPackage = this.PackagesCollection[temp];
            OnPropertyChanged("SelectedPackage");
            OnPropertyChanged("PackagesCollection");
            OnPropertyChanged("TotalPriceExTax");
        }

        private void ChangeSaleType()
        {
            if (this.IsWholesale)
            {
                foreach (Package p in this._pacs)
                {
                    p.UnitPrice = p.SaveWholesale;
                }
            }
            else
            {
                foreach (Package p in this._pacs)
                {
                    p.UnitPrice = p.SaveRetail;
                }
            }

            ObservableCollection<Package> tmpOb = new ObservableCollection<Package>();
            foreach (Package p in this._pacs)
            {
                tmpOb.Add(p);
            }

            this._pacs = tmpOb;
            OnPropertyChanged("PackagesCollection");
        }

        private void RemoveProduct()
        {
            this.SelectedPackage.PropertyChanged -= EntityViewModelPropertyChanged;
            this.PackagesCollection.Remove(this.SelectedPackage);
            this.SelectedPackage = null;
            OnPropertyChanged("SelectedPackage");
            OnPropertyChanged("PackagesCollection");
            OnPropertyChanged("TotalPriceExTax");
        }

        views.windows.AllProductsView dlg =  null;
        private void ChooseProduct()
        {
            dlg = new views.windows.AllProductsView();
            dlg.DataContext = this;
            if (dlg.ShowDialog() == true)
            {
                string description = this.Products[this.RowIndex].Description;
                string serialNo = this.Products[this.RowIndex].SerialNo;

                double price = this.Products[this.RowIndex].ImportPrice;
                this._currentPackage = Package.CreateBusinessPackage(serialNo, description, this.Products[this.RowIndex].CategoryName, price, 1, this.Products[this.RowIndex].Name);

                this._currentPackage.PackageUNK = "Pac-" + Guid.NewGuid().ToString();
                this._currentPackage.ProductUNK = this.Products[this.RowIndex].ProductUNK;

                this._currentPackage.SaveRetail = this.Products[this.RowIndex].RetailPrice;
                this._currentPackage.SaveWholesale = this.Products[this.RowIndex].WholesalePrice;
                this._currentPackage.SaveImportPrice = this.Products[this.RowIndex].ImportPrice;

                if (this.CanAddToPackageCollection)
                {
                    this.AddToPackageCollection();
                }
            }
        }

        private void AddProduct()
        {
            this._pacs.Add(Package.CreatePackage());
            this.SelectedPackage = this._pacs[this._pacs.Count - 1];
            OnPropertyChanged("SelectedPackage");
        }

        /// <summary>
        /// Execute search button (on search dialog)
        /// </summary>
        private void SearchProducts()
        {
            this._proRepo.LoadProductBySupplierAndCategory(this._currentSupplier.SupplierUNK, (this.SelectedCategory != null) ? this.SelectedCategory.CategoryUNK : string.Empty);

            if (string.IsNullOrEmpty(this.SelectedProperty))
            {
                this.Products = this._proRepo.GetProducts((this.SelectedCategory != null) ? this.SelectedCategory.CategoryUNK : string.Empty);
            }
            else
            {
                this.Products = this._proRepo.GetProductsWthSearchCriteria(
                    (this.SelectedCategory != null) ? this.SelectedCategory.CategoryUNK : string.Empty,
                    this.SelectedProperty,
                    this.SearchCriteria);
            }
        }

        /// <summary>
        /// Execute select product function (on search dialog)
        /// </summary>
        private void SelectProduct()
        {
            this.dlg.DialogResult = true;
            this.dlg.Close();
        }

        /// <summary>
        /// Execute close/cancel function (on search dialog)
        /// </summary>
        private void CloseProducts()
        {
            this.dlg.DialogResult = false;
            this.dlg.Close();
        }
        #endregion       

        #region Display suppliers View

        /// <summary>
        /// Represent ItemSource for select property selected in search dialog
        /// </summary>
        public Dictionary<string, string> SupplierFields { get; set; }

        /// <summary>
        /// Represent Property for search selected in search dialog
        /// </summary>
        public string SelectedSupplierProperty { get; set; }

        /// <summary>
        /// Represent Search Criteria typed in search dialog
        /// </summary>
        public string SearchSupplierCriteria { get; set; }

        /// <summary>
        /// Represent Index of row in listview selected in search dialog
        /// </summary>
        public int SupplierRowIndex { get; set; }

        /// <summary>
        /// Represent DataSource of listview for selecting product in search dialog
        /// </summary>
        public List<Supplier> Suppliers
        {
            get { return this._suppliers; }
            set { this._suppliers = value; base.OnPropertyChanged("Suppliers"); }
        }

        public DateTime InvoiceDate
        {
            get
            {
                return _invoiceDate;
            }
            set
            {
                if (!_invoiceDate.Equals(value))
                {
                    _invoiceDate = value;
                    OnPropertyChanged("InvoiceDate");
                }
            }
        }

        private RelayCommand _displaysuppliersCommand;
        private RelayCommand _selectsupplierCommand;
        private RelayCommand _closesuppliersCommand;
        private RelayCommand _searchsuppliersCommand;
        views.windows.AllSuppliersView supdlg = null;
        private List<Supplier> _suppliers;
        private DateTime _invoiceDate;

        public ICommand DisplaySupplierViewCommand
        {
            get
            {
                if (_displaysuppliersCommand == null)
                {
                    _displaysuppliersCommand = new RelayCommand(
                        (param) => this.DisplaysupplierView()
                        );
                }
                return _displaysuppliersCommand;
            }
        }

        public ICommand SelectSupplierCommand
        {
            get
            {
                if (_selectsupplierCommand == null)
                {
                    _selectsupplierCommand = new RelayCommand(
                        (param) => this.Selectsupplier(),(param)=>CanSelectSupplier
                        );
                }
                return _selectsupplierCommand;
            }
        }

        public ICommand CloseSuppliersCommand
        {
            get
            {
                if (_closesuppliersCommand == null)
                {
                    _closesuppliersCommand = new RelayCommand(
                        (param) => this.Closesuppliers()
                        );
                }
                return _closesuppliersCommand;
            }
        }

        public ICommand SearchSuppliersCommand
        {
            get
            {
                if (_searchsuppliersCommand == null)
                {
                    _searchsuppliersCommand = new RelayCommand(
                        (param) => this.SearchSupplier()
                        );
                }
                return _searchsuppliersCommand;
            }
        }

        /// <summary>
        /// Execute search button (on search dialog)
        /// </summary>
        private void SearchSupplier()
        {
            if (string.IsNullOrEmpty(this.SelectedSupplierProperty))
            {
                this.Suppliers = this._curSupplierRepository.GetSuppliers();
            }
            else
            {
                this.Suppliers = this._curSupplierRepository.GetSuppliersWthSearchCriteria(this.SelectedSupplierProperty, this.SearchSupplierCriteria);
            }
        }

        /// <summary>
        /// Execute select product function (on search dialog)
        /// </summary>
        private void Selectsupplier()
        {
            this.supdlg.DialogResult = true;
            this.supdlg.Close();
        }

        /// <summary>
        /// Execute close/cancel function (on search dialog)
        /// </summary>
        private void Closesuppliers()
        {
            this.supdlg.DialogResult = false;
            this.supdlg.Close();
        }

        private void DisplaysupplierView()
        {
            supdlg = new views.windows.AllSuppliersView();
            supdlg.DataContext = this;
            if (supdlg.ShowDialog() == true)
            {
                this._currentSupplier = this.Suppliers[this.SupplierRowIndex].CreateShallowCopy();
                this.SupplierCode = this.Suppliers[this.SupplierRowIndex].SupplierCode;
                this.Name = this.Suppliers[this.SupplierRowIndex].Name;
            }
        }
        #endregion

        public bool CanSelectSupplier { get { return SupplierRowIndex != -1 ? true : false; } }
        public bool CanSelectProduct { get { return RowIndex != -1 ? true : false; } }

        public override string DisplayName
        {
            get
            {
                try
                {
                    return Resources.Title_Receive;
                }
                catch (Exception ex)
                {
                    return string.Empty;
                }
            }

        }
    }
}
